package patrol.mobile.com.mobilepatrol.persenter;

import com.zhy.http.okhttp.callback.StringCallback;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.Map;

import okhttp3.Call;
import patrol.mobile.com.mobilepatrol.api.HttpUtils;
import patrol.mobile.com.mobilepatrol.view.QHMesView;

/**
 * Created by apple on 17/9/28.
 */

public class QHMesPer {
    public QHMesView mView;
    public Map<String, String> map;

    public QHMesPer(QHMesView mView, Map<String, String> map) {
        this.mView = mView;
        this.map = map;
    }

    public void getQHMes(String url) {
        HttpUtils.post(url, map).execute(new StringCallback() {
            @Override
            public void onError(Call call, Exception e, int id) {
                mView.hideLoading();
                mView.onQHError(e.getMessage());
            }

            @Override
            public void onResponse(String response, int id) {
                try {
                    JSONObject obj = new JSONObject(response);
                    int state = obj.optInt("state");
                    if (state==200){
                        mView.onQHSuccess(response);
                    }else{
                        mView.onQHError(obj.optString("message"));
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }




            }
        });
    }
}
